package controller.db_manager;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import jfinal.rest.ClassScanner;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by luob on 15/6/13.
 */
public class ModelMenuQueryInterceptor implements Interceptor {
    public void intercept(ActionInvocation ai) {
        Controller ctx = ai.getController();
        List<Class<?>> mclsssList = ClassScanner.scan("model");
        List<String> mStrList = new ArrayList<String>();
        for (Class<?> c : (null==mclsssList?new ArrayList<Class<?>>():mclsssList)) {
            mStrList.add(c.getName());
        }
        ctx.setAttr("mStrList", mStrList);

        List<Class<?>> scan = ClassScanner.scan("view");
        List<String> mViewStrList = new ArrayList<String>();
        for (Class<?> c : (null==scan?new ArrayList<Class<?>>():scan)) {
            mViewStrList.add(c.getName());
        }
        ctx.setAttr("mViewStrList", mViewStrList);

        ctx.setAttr("para", ctx.getPara());
        ai.invoke();
    }
}
